package com.hotec.PROJECT_NAME.config.encrypt;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

@Data
@ConfigurationProperties(prefix = "encrypt")
public class EncryptConfig {
    private String iv;

    private String alias;

    private String password;

    public char[] getPassword (){
        if(StrUtil.isBlank(this.password)){
            return new char[]{};
        }

        return this.password.toCharArray();
    }

    public byte[] getIv (){
        Charset charset = StandardCharsets.UTF_8;

        ByteBuffer encode = charset.encode(this.iv);

        return encode.array();
    }
}
